package com.ruoyi.control.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //添加
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.control.dto.MonkeyVehicleDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.control.mapper.MonkeyVehicleMapper;
import com.ruoyi.control.domain.MonkeyVehicle;
import com.ruoyi.control.service.IMonkeyVehicleService;

/**
 * 猴车Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-13
 */
@Service
public class MonkeyVehicleServiceImpl extends ServiceImpl<MonkeyVehicleMapper, MonkeyVehicle> implements IMonkeyVehicleService //修改
{
    @Autowired
    private MonkeyVehicleMapper monkeyVehicleMapper;

    /**
     * 查询猴车
     *
     * @param tagName 猴车主键
     * @return 猴车
     */
    @Override
    public MonkeyVehicle selectMonkeyVehicleByTagName(String tagName)
    {
        return monkeyVehicleMapper.selectMonkeyVehicleByTagName(tagName);
    }

    /**
     * 查询猴车列表
     *
     * @param monkeyVehicle 猴车
     * @return 猴车
     */
    @Override
    public List<MonkeyVehicle> selectMonkeyVehicleList(MonkeyVehicle monkeyVehicle)
    {
        return monkeyVehicleMapper.selectMonkeyVehicleList(monkeyVehicle);
    }

    /**
     * 新增猴车
     *
     * @param monkeyVehicle 猴车
     * @return 结果
     */
    @Override
    public int insertMonkeyVehicle(MonkeyVehicle monkeyVehicle)
    {
        return monkeyVehicleMapper.insertMonkeyVehicle(monkeyVehicle);
    }

    /**
     * 修改猴车
     *
     * @param monkeyVehicle 猴车
     * @return 结果
     */
    @Override
    public int updateMonkeyVehicle(MonkeyVehicle monkeyVehicle)
    {
        monkeyVehicle.setUpdateTime(DateUtils.getNowDate());
        return monkeyVehicleMapper.updateMonkeyVehicle(monkeyVehicle);
    }

    /**
     * 批量删除猴车
     *
     * @param tagNames 需要删除的猴车主键
     * @return 结果
     */
    @Override
    public int deleteMonkeyVehicleByTagNames(String[] tagNames)
    {
        return monkeyVehicleMapper.deleteMonkeyVehicleByTagNames(tagNames);
    }

    /**
     * 删除猴车信息
     *
     * @param tagName 猴车主键
     * @return 结果
     */
    @Override
    public int deleteMonkeyVehicleByTagName(String tagName)
    {
        return monkeyVehicleMapper.deleteMonkeyVehicleByTagName(tagName);
    }

    @Override
    public List<MonkeyVehicleDto> getSSData() {
        MonkeyVehicleDto monkeyVehicleDto1 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto2 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto3 =new MonkeyVehicleDto();
        monkeyVehicleDto1.setTagName1("网络连接");
        monkeyVehicleDto1.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("井下停止").getValue());
        monkeyVehicleDto1.setTagName2("运行速度");
        monkeyVehicleDto1.setStatus2(String.valueOf(Double.valueOf(monkeyVehicleMapper.selectMonkeyVehicleByDescription("拖轮速度显示").getValue())
        /100)+"m/s");
        monkeyVehicleDto2.setTagName1("运行模式");
        if("true".equals(monkeyVehicleMapper.selectMonkeyVehicleByDescription("连续模式").getValue())){
            monkeyVehicleDto2.setStatus1("连续");
        }
        if("true".equals(monkeyVehicleMapper.selectMonkeyVehicleByDescription("间断模式").getValue())){
            monkeyVehicleDto2.setStatus1("间断");
        }
        if("true".equals(monkeyVehicleMapper.selectMonkeyVehicleByDescription("检修模式").getValue())){
            monkeyVehicleDto2.setStatus1("检修");
        }
        monkeyVehicleDto2.setTagName2("预警时间");
        //monkeyVehicleDto2.setStatus2(monkeyVehicleMapper.selectMonkeyVehicleByDescription("预警倒计时").getValue()+"s");
        monkeyVehicleDto2.setStatus2("0s");
        monkeyVehicleDto3.setTagName1("控制模式");
        if("true".equals(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控切换按钮").getValue()) &&
                "true".equals(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控切换执行").getValue())){
            monkeyVehicleDto3.setStatus1("近控");
        }else {
            monkeyVehicleDto3.setStatus1("远控");
        }
        monkeyVehicleDto3.setTagName2("间断时间");
        monkeyVehicleDto3.setStatus2(monkeyVehicleMapper.selectMonkeyVehicleByDescription("间断运行时长倒计时数显").getValue()+"s");
        List<MonkeyVehicleDto> monkeyVehicleDtoList =new ArrayList<>();
        monkeyVehicleDtoList.add(monkeyVehicleDto1);
        monkeyVehicleDtoList.add(monkeyVehicleDto2);
        monkeyVehicleDtoList.add(monkeyVehicleDto3);
        return monkeyVehicleDtoList;
    }

    @Override
    public List<MonkeyVehicleDto> getControlData() {
        MonkeyVehicleDto monkeyVehicleDto1 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto2 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto3 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto4 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto5 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto6 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto7 =new MonkeyVehicleDto();
        monkeyVehicleDto1.setTagName1("远近切换");
        monkeyVehicleDto1.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控切换执行").getValue());
        monkeyVehicleDto2.setTagName1("开车预警");
        monkeyVehicleDto2.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控开车预警").getValue());
        monkeyVehicleDto3.setTagName1("远程启动");
        monkeyVehicleDto3.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控启动").getValue());
        monkeyVehicleDto4.setTagName1("远程停止");
        monkeyVehicleDto4.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控停车").getValue());
        monkeyVehicleDto5.setTagName1("故障复位");
        monkeyVehicleDto5.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控故障复位").getValue());
        monkeyVehicleDto6.setTagName1("报警消音");
        monkeyVehicleDto6.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控报警消音").getValue());
        monkeyVehicleDto7.setTagName1("远程急停");
        monkeyVehicleDto7.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("集控急停禁启").getValue());
        List<MonkeyVehicleDto> monkeyVehicleDtoList=new ArrayList<>();
        monkeyVehicleDtoList.add(monkeyVehicleDto1);
        monkeyVehicleDtoList.add(monkeyVehicleDto2);
        monkeyVehicleDtoList.add(monkeyVehicleDto3);
        monkeyVehicleDtoList.add(monkeyVehicleDto4);
        monkeyVehicleDtoList.add(monkeyVehicleDto5);
        monkeyVehicleDtoList.add(monkeyVehicleDto6);
        monkeyVehicleDtoList.add(monkeyVehicleDto7);
        return monkeyVehicleDtoList;
    }

    @Override
    public List<MonkeyVehicleDto> getStatusData() {
        MonkeyVehicleDto monkeyVehicleDto1 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto2 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto3 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto4 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto5 =new MonkeyVehicleDto();
        MonkeyVehicleDto monkeyVehicleDto6 =new MonkeyVehicleDto();
        monkeyVehicleDto1.setTagName1("主电机");
        monkeyVehicleDto1.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("主电机指示").getValue());
        monkeyVehicleDto1.setTagName2("电磁阀1");
        monkeyVehicleDto1.setStatus2("false");
        monkeyVehicleDto1.setTagName3("急停禁启");
        monkeyVehicleDto1.setStatus3(monkeyVehicleMapper.selectMonkeyVehicleByDescription("急停禁启按钮信号汇总").getValue());

        monkeyVehicleDto2.setTagName1("工作闸电机");
        monkeyVehicleDto2.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("工作闸电机指示").getValue());
        monkeyVehicleDto2.setTagName2("电磁阀2");
        monkeyVehicleDto2.setStatus2("false");
        monkeyVehicleDto2.setTagName3("设备互锁");
        monkeyVehicleDto2.setStatus3("true");

        monkeyVehicleDto3.setTagName1("安全闸电机");
        monkeyVehicleDto3.setStatus1(monkeyVehicleMapper.selectMonkeyVehicleByDescription("安全闸电机指示").getValue());
        monkeyVehicleDto3.setTagName2("开车预警");
        monkeyVehicleDto3.setStatus2(monkeyVehicleMapper.selectMonkeyVehicleByDescription("开车预警指示").getValue());
        monkeyVehicleDto3.setTagName3("急停位置");
        monkeyVehicleDto3.setStatus3(monkeyVehicleMapper.selectMonkeyVehicleByDescription("沿线急停位置").getValue());
        monkeyVehicleDto3.setStatus3("0");

        monkeyVehicleDto4.setTagName2("故障预警");
        monkeyVehicleDto4.setStatus2(monkeyVehicleMapper.selectMonkeyVehicleByDescription("开车预警指示").getValue());
        monkeyVehicleDto4.setTagName3("掉绳位置");
        //monkeyVehicleDto4.setStatus3(monkeyVehicleMapper.selectMonkeyVehicleByDescription("沿线急停位置").getValue());
        monkeyVehicleDto4.setStatus3("0");

        monkeyVehicleDto5.setTagName3("检修时间");
        monkeyVehicleDto5.setStatus3(monkeyVehicleMapper.selectMonkeyVehicleByDescription("换油时长显示").getValue()+"h");

        monkeyVehicleDto6.setTagName3("换油时间");
        monkeyVehicleDto6.setStatus3(monkeyVehicleMapper.selectMonkeyVehicleByDescription("换油时长显示").getValue()+"h");

        List<MonkeyVehicleDto> monkeyVehicleDtoList=new ArrayList<>();
        monkeyVehicleDtoList.add(monkeyVehicleDto1);
        monkeyVehicleDtoList.add(monkeyVehicleDto2);
        monkeyVehicleDtoList.add(monkeyVehicleDto3);
        monkeyVehicleDtoList.add(monkeyVehicleDto4);
        monkeyVehicleDtoList.add(monkeyVehicleDto5);
        monkeyVehicleDtoList.add(monkeyVehicleDto6);
        return monkeyVehicleDtoList;
    }

    @Override
    public List<MonkeyVehicleDto> getIndicatorData() {
        List<MonkeyVehicle> monkeyVehicleList = monkeyVehicleMapper.selectMonkeyVehicleByLikeDescription("信号");
        List<MonkeyVehicleDto> dtoList = new ArrayList<>();
        for (int start = 0; start < monkeyVehicleList.size(); start += 3) {
            List<MonkeyVehicle> monkeyVehicleList1 = monkeyVehicleList.subList(start, Math.min(start + 3, monkeyVehicleList.size()));
            MonkeyVehicleDto dto = new MonkeyVehicleDto();

            for (int j = 0; j < monkeyVehicleList1.size(); j++) {
                MonkeyVehicle mv = monkeyVehicleList1.get(j);
                switch (j) {
                    case 0:
                        dto.setTagName1(mv.getDescription());
                        dto.setStatus1(mv.getValue());
                        break;
                    case 1:
                        dto.setTagName2(mv.getDescription());
                        dto.setStatus2(mv.getValue());
                        break;
                    case 2:
                        dto.setTagName3(mv.getDescription());
                        dto.setStatus3(mv.getValue());
                        break;
                }
            }
            dtoList.add(dto);
        }

        return dtoList;
    }

}
